package cn.liip.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.liip.demo.service.UserService;
import cn.liip.demo.domain.User;

@RestController
public class UserController {
	@Autowired
	private UserService userService;

	/**
	 * 访问地址：http://localhost:8080/users/老王
	 * 
	 * @param userName
	 * @return
	 */
	@RequestMapping(value = "/users/{userName}")
	public List<User> findUsers(@PathVariable String userName) {

		List<User> users = userService.findByUsername(userName);

		return users;
	}

	/**
	 * 访问地址：http://localhost:8080/user/1
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/user/{id}")
	public User getUser(@PathVariable Integer id) {
		User user = userService.findById(id);
		return user;
	}
}